package com.xc.service.Impl;

import com.xc.dao.PermissionMapper;
import com.xc.pojo.Permission;
import com.xc.service.PermissionService;
import com.xc.vo.PermissionVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Resource
    private PermissionMapper permissionMapper;
    /**
     * 查询菜单列表
     * @param permissionVo
     * @return
     */
    public List<Permission> queryPermissionList(PermissionVo permissionVo) {
        return permissionMapper.queryPermissionList(permissionVo);
    }
    /**
     * 添加菜单
     * @return
     */
    public int addMenu(Permission permission) {
        if (permission.getPid()==null){//判断是否选择一级菜单
            permission.setPid(0);//0表示一级菜单
        }
        permission.setTarget("_self");//在自身窗口打开
        return permissionMapper.addMenu(permission);
    }
    /**
     * 修改菜单
     * @return
     */
    public int updateMenu(Permission permission) {
        return permissionMapper.updateMenu(permission);
    }

    public int queryPermissionCountById(Integer id) {
        return permissionMapper.queryPermissionCountById(id);
    }

    public int deleteMenu(Integer id) {
        return permissionMapper.deleteById(id);
    }

    public List<Permission> findPermissionListByUserId(Integer userId, String type) {
        return permissionMapper.findPermissionListByUserId(userId,type);
    }
}
